from rest_framework import serializers

from home.models import Gps, Course, Img, Tupian


class GpsSerializer(serializers.ModelSerializer):
    class Meta:
        model = Gps
        fields = ['id','name','display_name','weight','url','wailian']

class CourseSerializer(serializers.ModelSerializer):
    children = serializers.SerializerMethodField()
    class Meta:
        model = Course
        fields = ['id','name','level','dep','children']

    def get_children(self,obj):
        print(obj)
        children = Course.objects.filter(parent=obj)
        if children:
            serializer = CourseSerializer(children,many=True)
            return serializer.data
        else:
            return []

class ImgSerializer(serializers.ModelSerializer):
    class Meta:
        model = Img
        fields = ['id','name','img','note','link']

#定义上传图片的序列化器
class TupianSerializer(serializers.ModelSerializer):
    class Meta:
        model = Tupian
        fields = '__all__'
































































